<template>
  <div class="view_page applist">
    <el-card class="box-card">
      <!--卡片头部-->
      <div slot="header" class="clearfix">
        <!--左侧-->
        <div class="left">
          <div class="menu-title">
            配置业务
          </div>
        </div>
        <div class="right">
          <el-button type="primary" size="small" @click="save()"
            >保存
          </el-button>
        </div>
      </div>
      <div class="query-operate">
        <div style="display: flex;">
          <el-form
            class="demo-form-inline indoor-scene-buzhou-list-form"
            :inline="true"
            :model="TESTFROMDATA"
            @submit.native.prevent
          >
            <el-form-item
              label="水库"
              label-width="60px"
              style="margin-top: 5px; margin-bottom: 5px;"
            >
              <el-select
                v-model="TESTFROMDATA.sk"
                @change="changeSK()"
                filterable
              >
                <el-option
                  v-for="item in skList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <!--卡片内容-->
      <div class="card-centont">
        <el-form :model="liveData" label-width="120px">
          <el-form-item label="初始化地址">
            <el-input
              v-model="liveData.init_address"
              clearable
              placeholder="请输入初始化地址"
            ></el-input>
          </el-form-item>
          <el-form-item label="业务地址">
            <el-input
              v-model="liveData.work_address"
              clearable
              placeholder="请输入业务地址"
            ></el-input>
          </el-form-item>
          <el-form-item label="配置地址">
            <el-input
              v-model="liveData.conf_address"
              clearable
              placeholder="请输入配置地址"
            ></el-input>
          </el-form-item>
          <el-form-item label="配置Json">
            <el-input
              v-model="liveData.conf_json"
              clearable
              placeholder="请输入配置Json"
            ></el-input>
          </el-form-item>
        </el-form>
        <!-- <el-button type="primary" @click="save()" size="medium">保存</el-button> -->
      </div>
    </el-card>
  </div>
</template>

<script>
import { Message } from "element-ui";
import pagination from "@/components/common/pagination/pagination";

export default {
  components: {
    pagination
  },
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem("loginPersonnelInformation")),
      // 筛选内容
      TESTFROMDATA: {
        sk: ""
      },
      skList: [
        {
          id: -1,
          name: "全部"
        },
        {
          id: 1,
          name: "大河水库"
        },
        {
          id: 2,
          name: "马河水库"
        }
      ],
      //富文本文档类型
      liveData: {
        init_address: "",
        work_address: "",
        conf_address: "",
        conf_json: ""
      }
    };
  },
  created() {
    this.initData();
    this.getAppData();
  },
  mounted() {},
  methods: {
    initData() {
      this.liveData = {
        init_address: "",
        work_address: "",
        conf_address: "",
        conf_json: ""
      };
    },
    changeSK() {
      var _this = this;
      console.log(_this.TESTFROMDATA.sk);
    },
    //查询
    getAppData() {
      var _this = this;
      _this.$apis.u_config_query().then(res => {
        if (res.result == 0) {
          this.liveData = res.data;
        }
      });
    },
    //保存
    save() {
      var _this = this;
      var datas = _this.liveData;
      // var reg = /^((https?|ftp):\/\/)?([\da-z.-]+)\.([a-z.]{2,6})(\/\w\.-]*)*\/?/;
      var reg = /(https?|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/;
      if (datas.init_address == "") {
        Message.error("初始化地址不能为空");
        return;
      }
      if (!reg.test(datas.init_address)) {
        Message.error("请填写正确格式的初始化地址");
        return;
      }
      if (datas.work_address == "") {
        Message.error("业务地址不能为空");
        return;
      }
      if (!reg.test(datas.work_address)) {
        Message.error("请填写正确格式的业务地址");
        return;
      }
      if (datas.conf_address == "") {
        Message.error("配置地址不能为空");
        return;
      }
      if (!reg.test(datas.conf_address)) {
        Message.error("请填写正确格式的配置地址");
        return;
      }
      if (datas.conf_json == "") {
        Message.error("配置Json不能为空");
        return;
      }
      // console.log("datas:", datas);
      _this.$apis.u_config_update(datas).then(res => {
        if (res.result == 0) {
          Message.success(res.msg);
          this.getAppData();
        } else {
          Message.error(res.msg);
        }
      });
    }
  }
};
</script>

<style lang="scss">
.detailFormClass {
  margin: 0 20px;

  .el-input__inner,
  .el-textarea__inner {
    border: none;
  }

  .el-input.is-disabled .el-input__inner,
  .el-textarea.is-disabled .el-textarea__inner {
    background: #fff;
    cursor: default;
    color: #000;
  }
}
</style>
